//
//  PDFViewer.swift
//  ptbuy
//
//  Created by MyMac on 2024/11/28.
//

import SwiftUI
import UIKit
import PDFKit

/*
  pdf文件预览
 */
struct PDFViewerUtils: View {
    var url: URL

    var body: some View {
        PDFViewWrapper(url: url)
            .edgesIgnoringSafeArea(.all)
    }
}

struct PDFViewWrapper: UIViewRepresentable {
    var url: URL

    func makeUIView(context: Context) -> PDFView {
        let pdfView = PDFView()
        pdfView.autoScales = true// 自动缩放以适应屏幕
        return pdfView
    }

    func updateUIView(_ uiView: PDFView, context: Context) {
        // 加载 PDF 文件
        if let document = PDFDocument(url: url) {
            uiView.document = document
        }
    }
}
